package com.mkz.jbpm.activiti.impl;

import java.util.List;

import org.activiti.engine.history.HistoricTaskInstance;
import org.activiti.engine.history.HistoricTaskInstanceQuery;
import org.springframework.stereotype.Component;

import com.mkz.jbpm.activiti.ActHistTaskQueryService;
import com.mkz.jbpm.activiti.base.ActServiceFactory;

/**
 * ClassName: ActHistTaskQueryServiceImpl 
 * @Description: 历史任务
 * @author: KuangJianyu
 * @date: 2020年4月3日
 */
@Component
public class ActHistTaskQueryServiceImpl extends ActServiceFactory implements ActHistTaskQueryService {

    @Override
    public HistoricTaskInstanceQuery createHistoricTaskInstanceQuery() {
        return historyService.createHistoricTaskInstanceQuery();
    }

    @Override
    public HistoricTaskInstance activeTask(String instanceId) {
        return createHistoricTaskInstanceQuery().processInstanceId(instanceId).unfinished().singleResult();
    }

    @Override
    public HistoricTaskInstance finishedTask(String taskId) {
        return createHistoricTaskInstanceQuery().taskId(taskId).singleResult();
    }

    @Override
    public List<HistoricTaskInstance> listByInstanceId(String instanceId) {
        return createHistoricTaskInstanceQuery().processInstanceId(instanceId).orderByTaskCreateTime().desc().list();
    }

    @Override
    public List<HistoricTaskInstance> pageListByInstanceId(String instanceId, int start, int limit) {
        return createHistoricTaskInstanceQuery()
                .processInstanceId(instanceId)
                .orderByTaskCreateTime()
                .desc().listPage(start, limit);
    }
    
    @Override
    public List<HistoricTaskInstance> pageListByUserid(String userid, int start, int limit){
    	return createHistoricTaskInstanceQuery()
    			.taskAssignee(userid)
    			.finished().listPage(start, limit);
    }
}